import { getCommentApi } from "../../services/axios";
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";


interface Comment {
    username:string
    avatar:string
    deliveryTime:number
    rateTime:number
    text:string
    score:number
    recommend:string[]
    rateType:number
}

interface initialState {
    commentList:Comment[]
}


const initialState:initialState = {
    commentList:[]
}

export const getComment = createAsyncThunk('comment/getComment', async () => {
    const res = await getCommentApi()
    // console.log(res.data)
    return res.data.data
})



const commentSlice = createSlice({
    name:'comment',
    initialState,
    reducers:{

    },
    extraReducers:builder => {
        builder
            .addCase(getComment.fulfilled,(state,action) => {
                // console.log(action.payload)
                // console.log(state.commentList)
                state.commentList = action.payload
            })
    }
})


export default commentSlice.reducer